import requests
import re
import time

def ipsp():
	url = 'http://www.xicidaili.com/wn/'
	header = {'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Mobile Safari/537.36'}
	r = requests.get(url,headers=header).text
	pat = '<td class="country"><img.*?<td>(.*?)</td>.*?<td>(.*?)</td>'
	ip_list = re.compile(pat,re.S).findall(r)
	ip_pool = []
	for i in range(0,len(ip_list)):
		ip = str(ip_list[i][0]+':'+ip_list[i][1]+'\n')
		ip_pool.append(ip)
	with open(r'C:\Users\Administrator\Desktop\Python\ip.txt','w',encoding='utf-8') as f:
		f.writelines(ip_pool)
#	time.sleep(40)
	
ipsp()
